<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>CovidContagionCalibrator &mdash; Melodie 0.6.0 documentation</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../_static/doctools.js"></script>
        <script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script src="../_static/js/theme.js"></script>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="RockPaperScissorsTrainer" href="rock_paper_scissors.html" />
    <link rel="prev" title="CovidNetworkContagion" href="covid_network_contagion.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../index.html" class="icon icon-home"> Melodie
            <img src="../_static/logo.jpg" class="logo" alt="Logo"/>
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../installation.html#user-installation">User Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation.html#developer-installation">Developer Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation.html#dependency-note">Dependency Note</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../introduction.html#agent-based-model-abm">Agent-based Model (ABM)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introduction.html#melodie-framework">Melodie Framework</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../introduction.html#model">Model</a></li>
<li class="toctree-l3"><a class="reference internal" href="../introduction.html#scenario">Scenario</a></li>
<li class="toctree-l3"><a class="reference internal" href="../introduction.html#modelling-manager">Modelling Manager</a></li>
<li class="toctree-l3"><a class="reference internal" href="../introduction.html#infrastructure">Infrastructure</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#project-structure">Project Structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#agent">Agent</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#scenario">Scenario</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial.html#generate-agent-params">Generate <code class="docutils literal notranslate"><span class="pre">agent_params</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial.html#load-simulator-scenarios">Load <code class="docutils literal notranslate"><span class="pre">simulator_scenarios</span></code></a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#model">Model</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#environment">Environment</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#datacollector">DataCollector</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial.html#last-words">Last Words</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../framework_comparison.html">Framework Comparison</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../framework_comparison.html#project-structure">Project Structure</a></li>
<li class="toctree-l2"><a class="reference internal" href="../framework_comparison.html#model-components">Model Components</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#melodie">Melodie</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id2">Mesa</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id3">AgentPy</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#summary">Summary</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../framework_comparison.html#scenario-management">Scenario Management</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id4">Melodie</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id5">Mesa</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id6">AgentPy</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#id7">Summary</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../framework_comparison.html#modeling-manager">Modeling Manager</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#calibrator">Calibrator</a></li>
<li class="toctree-l3"><a class="reference internal" href="../framework_comparison.html#trainer">Trainer</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="_index.html">Model Gallery</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="covid_grid_contagion.html">CovidGridContagion</a><ul>
<li class="toctree-l3"><a class="reference internal" href="covid_grid_contagion.html#project-structure">Project Structure</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_grid_contagion.html#grid-and-spot">Grid and Spot</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_grid_contagion.html#matrix-data">Matrix Data</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_grid_contagion.html#model">Model</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_grid_contagion.html#gridagent">GridAgent</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="covid_network_contagion.html">CovidNetworkContagion</a><ul>
<li class="toctree-l3"><a class="reference internal" href="covid_network_contagion.html#project-structure">Project Structure</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_network_contagion.html#model">Model</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_network_contagion.html#scenario">Scenario</a></li>
</ul>
</li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">CovidContagionCalibrator</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#project-structure">Project Structure</a></li>
<li class="toctree-l3"><a class="reference internal" href="#calibrator">Calibrator</a></li>
<li class="toctree-l3"><a class="reference internal" href="#algorithm">Algorithm</a></li>
<li class="toctree-l3"><a class="reference internal" href="#results">Results</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="rock_paper_scissors.html">RockPaperScissorsTrainer</a><ul>
<li class="toctree-l3"><a class="reference internal" href="rock_paper_scissors.html#model-setup">Model Setup</a></li>
<li class="toctree-l3"><a class="reference internal" href="rock_paper_scissors.html#trainer">Trainer</a></li>
<li class="toctree-l3"><a class="reference internal" href="rock_paper_scissors.html#results">Results</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="covid_contagion_visual.html">CovidContagionVisual</a><ul>
<li class="toctree-l3"><a class="reference internal" href="covid_contagion_visual.html#visualizer">Visualizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_contagion_visual.html#melodiestudio">MelodieStudio</a></li>
<li class="toctree-l3"><a class="reference internal" href="covid_contagion_visual.html#how-to-start">How to start?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/_index.html">Advanced Topics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../advanced/troubleshooting.html">TroubleShooting</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../advanced/troubleshooting.html#port-already-in-use">Port Already in use</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../advanced/troubleshooting.html#windows">Windows</a></li>
<li class="toctree-l4"><a class="reference internal" href="../advanced/troubleshooting.html#macos-linux-or-other-nix-systems">MacOS, Linux or other *nix systems</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../advanced/melodie_error_list.html">Melodie Errors</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api/_index.html">API Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../api/model.html">Model</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/agent.html">Agent</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/agent_list.html">AgentList</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/environment.html">Environment</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/data_collector.html">DataCollector</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/grid.html">Grid</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/network.html">Network</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/data_info.html">DataInfo</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../api/data_info.html#dataframeinfo">DataFrameInfo</a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/data_info.html#matrixinfo">MatrixInfo</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../api/data_loader.html">DataLoader</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/scenario.html">Scenario</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/simulator.html">Simulator</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/calibrator.html">Calibrator</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/trainer.html">Trainer</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/db.html">DB</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/exceptions.html">Melodie Exceptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../changelog.html">Change Log</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#major-version-0-x">Major Version 0.x</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-6-0-jan-04-2023">v0.6.0 (Jan. 04, 2023)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-5-0-dec-17-2022">v0.5.0 (Dec. 17, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-4-2-dec-15-2022">v0.4.2 (Dec. 15, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-4-1-dec-12-2022">v0.4.1 (Dec. 12, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-4-0-nov-15-2022">v0.4.0 (Nov. 15, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-3-0-oct-28-2022">v0.3.0 (Oct. 28, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-2-0-oct-24-2022">v0.2.0 (Oct. 24, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-1-1-aug-23-2022">v0.1.1 (Aug. 23, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#v0-1-0-jul-22-2022">v0.1.0 (Jul. 22, 2022)</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#start-may-10-2021">Start (May. 10, 2021)</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../contribution.html">Contribution</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../contribution.html#report-bugs">Report Bugs</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../contribution.html#report-melodie-bugs">Report Melodie Bugs</a></li>
<li class="toctree-l3"><a class="reference internal" href="../contribution.html#report-documentation-bugs">Report Documentation Bugs</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../contribution.html#ask-for-functionalities">Ask for Functionalities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contribution.html#how-to-contribute">How to Contribute</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../about.html">About</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Melodie</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
          <li><a href="_index.html">Model Gallery</a> &raquo;</li>
      <li>CovidContagionCalibrator</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/gallery/covid_contagion_calibrator.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="covidcontagioncalibrator">
<h1>CovidContagionCalibrator<a class="headerlink" href="#covidcontagioncalibrator" title="Permalink to this heading"></a></h1>
<p>To show how the <code class="docutils literal notranslate"><span class="pre">Calibrator</span></code> module can be used,
we provide this <a class="reference external" href="https://github.com/ABM4ALL/CovidContagionCalibrator">CovidContagionCalibrator</a> model,
which is almost same with the <a class="reference external" href="https://github.com/ABM4ALL/CovidContagion">CovidContagion</a> model.
The only difference is that, we can run it with another <a class="reference internal" href="../introduction.html#modelling-manager"><span class="std std-ref">Modelling Manager</span></a> - <code class="docutils literal notranslate"><span class="pre">Calibrator</span></code>.
So, if you haven’t, we will strongly suggest to read the <a class="reference internal" href="../tutorial.html#tutorial"><span class="std std-ref">Tutorial</span></a> section first.</p>
<section id="project-structure">
<h2>Project Structure<a class="headerlink" href="#project-structure" title="Permalink to this heading"></a></h2>
<p>The project structure is as below.
Compared with the structure of the <a class="reference external" href="https://github.com/ABM4ALL/CovidContagion">CovidContagion</a> model,
two python files - <code class="docutils literal notranslate"><span class="pre">calibrator.py</span></code> and <code class="docutils literal notranslate"><span class="pre">run_calibrator</span></code> - files are added in the <code class="docutils literal notranslate"><span class="pre">source</span></code> and the <code class="docutils literal notranslate"><span class="pre">root</span></code> folders,
and two excel files - <code class="docutils literal notranslate"><span class="pre">CalibratorScenarios.xlsx</span></code> and <code class="docutils literal notranslate"><span class="pre">CalibratorParamsScenarios.xlsx</span></code> - are added in the <code class="docutils literal notranslate"><span class="pre">data/input</span></code> folder.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>CovidContagionCalibrator
├── data
│   ├── input
│   │   ├── SimulatorScenarios.xlsx
│   │   ├── CalibratorScenarios.xlsx
│   │   ├── CalibratorParamsScenarios.xlsx
│   │   ├── ID_HealthState.xlsx
│   │   ├── ID_AgeGroup.xlsx
│   │   └── Parameter_AgeGroup_TransitionProb.xlsx
│   └── output
│       ├── CovidGridContagionCalibrator.sqlite
│       ├── PopulationInfection_S0R0.png
│       └── PopulationInfection_S1R0.png
├── source
│   ├── agent.py
│   ├── environment.py
│   ├── grid.py
│   ├── data_collector.py
│   ├── data_info.py
│   ├── data_loader.py
│   ├── scenario.py
│   ├── model.py
│   ├── calibrator.py
│   └── analyzer.py
├── config.py
├── run_simulator.py
├── run_calibrator.py
├── run_analyzer.py
└── readme.md
</pre></div>
</div>
</section>
<section id="calibrator">
<h2>Calibrator<a class="headerlink" href="#calibrator" title="Permalink to this heading"></a></h2>
<p>The idea of <code class="docutils literal notranslate"><span class="pre">Calibrator</span></code> in <code class="docutils literal notranslate"><span class="pre">Melodie</span></code> is to find the values of pre-defined parameters
- attributes of the <code class="docutils literal notranslate"><span class="pre">scenario</span></code> object -
so that the distance between model output and empirical data is minimized.
In this example, we want to find the value of <code class="docutils literal notranslate"><span class="pre">scenario.infection_prob</span></code>,
so that  by the end of the simulation, the share of uninfected population is 50%.</p>
<p>For this, one file <code class="docutils literal notranslate"><span class="pre">calibrator.py</span></code> is added in the <code class="docutils literal notranslate"><span class="pre">source</span></code> folder.</p>
<div class="literal-block-wrapper docutils container" id="id3">
<div class="code-block-caption"><span class="caption-text">calibrator.py</span><a class="headerlink" href="#id3" title="Permalink to this code"></a></div>
<div class="highlight-Python notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span><span class="kn">from</span> <span class="nn">Melodie</span> <span class="kn">import</span> <span class="n">Calibrator</span>
<span class="linenos"> 2</span>
<span class="linenos"> 3</span><span class="kn">from</span> <span class="nn">source.environment</span> <span class="kn">import</span> <span class="n">CovidEnvironment</span>
<span class="linenos"> 4</span>
<span class="linenos"> 5</span>
<span class="linenos"> 6</span><span class="k">class</span> <span class="nc">CovidCalibrator</span><span class="p">(</span><span class="n">Calibrator</span><span class="p">):</span>
<span class="linenos"> 7</span>
<span class="linenos"> 8</span>    <span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="linenos"> 9</span>        <span class="bp">self</span><span class="o">.</span><span class="n">add_scenario_calibrating_property</span><span class="p">(</span><span class="s2">&quot;infection_prob&quot;</span><span class="p">)</span>
<span class="hll"><span class="linenos">10</span>        <span class="bp">self</span><span class="o">.</span><span class="n">add_environment_property</span><span class="p">(</span><span class="s2">&quot;s0&quot;</span><span class="p">)</span>
</span><span class="linenos">11</span>
<span class="linenos">12</span>    <span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">:</span> <span class="s2">&quot;CovidModel&quot;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
<span class="linenos">13</span>        <span class="n">environment</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">environment</span>
<span class="hll"><span class="linenos">14</span>        <span class="k">return</span> <span class="p">(</span><span class="n">environment</span><span class="o">.</span><span class="n">s0</span> <span class="o">/</span> <span class="n">environment</span><span class="o">.</span><span class="n">scenario</span><span class="o">.</span><span class="n">agent_num</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span>
</span></pre></div>
</div>
</div>
<p>Two functions are defined in this <code class="docutils literal notranslate"><span class="pre">CovidCalibrator</span></code> class.</p>
<p>First, in the <code class="docutils literal notranslate"><span class="pre">setup</span></code> function, by using the <code class="docutils literal notranslate"><span class="pre">add_scenario_calibrating_property</span></code> function,
we define which attribute of the <code class="docutils literal notranslate"><span class="pre">scenario</span></code> will be calibrated.
<code class="docutils literal notranslate"><span class="pre">Melodie</span></code> supports adding multiple parameters by calling the function again and passing in the name of the attribute.
However, in general, the more parameters you want to calibrate,
the longer time it could take and the lower quality of the results might be.
Additionally, as shown in Line 10, you can also <code class="docutils literal notranslate"><span class="pre">add_environment_property</span></code> so that they can be included in the result tables (see below).</p>
<p>Second, in the <code class="docutils literal notranslate"><span class="pre">distance</span></code> function,
you can define how the distance between the <strong>model output</strong> and the <strong>empirical data</strong> is measured.
The parameter of the <code class="docutils literal notranslate"><span class="pre">distance</span></code> function must be <code class="docutils literal notranslate"><span class="pre">model</span></code>,
so that all the input data can be accessed through <code class="docutils literal notranslate"><span class="pre">model.scenario</span></code>,
and all the macro- and micro-variables can be accessed through <code class="docutils literal notranslate"><span class="pre">model.environment</span></code> and <code class="docutils literal notranslate"><span class="pre">model.agents</span></code>.
But, please note that, the values are all the values by the end of the simulation.
In this example, the calibration target is “50% of the agents are not infected by the end of simulation”,</p>
</section>
<section id="algorithm">
<h2>Algorithm<a class="headerlink" href="#algorithm" title="Permalink to this heading"></a></h2>
<p>In the current version, <code class="docutils literal notranslate"><span class="pre">Melodie</span></code> applies the <a class="reference external" href="https://en.wikipedia.org/wiki/Genetic_algorithm">genetic algorithm (GA)</a>
to search the parameter space.
Relevant parameters are defined in the <code class="docutils literal notranslate"><span class="pre">CalibratorParamsScenarios.xlsx</span></code> file.</p>
<img alt="../_images/calibrator_params.png" src="../_images/calibrator_params.png" />
<p>Please note that,</p>
<ul class="simple">
<li><p>First, in this model, we are only calibrating one parameter <code class="docutils literal notranslate"><span class="pre">infection_prob</span></code> and its space is <span class="math notranslate nohighlight">\([0, 1]\)</span>, as defined in the table by attributes <code class="docutils literal notranslate"><span class="pre">infection_prob_min</span></code> and <code class="docutils literal notranslate"><span class="pre">infection_prob_max</span></code>.</p></li>
<li><p>Second, the attribute <code class="docutils literal notranslate"><span class="pre">strategy_param_code_length</span></code> decides the length of the binary series used to code the parameter being calibrated. In the GA, it is the length of “chromosome”. The longer it is, the higher accuracy of the coding is and the longer it might take for the calibration.</p></li>
<li><p>Third, the <code class="docutils literal notranslate"><span class="pre">generation_num</span></code>, <code class="docutils literal notranslate"><span class="pre">strategy_population</span></code>, and <code class="docutils literal notranslate"><span class="pre">mutation_prob</span></code> are the three common parameters in GA. The larger the <code class="docutils literal notranslate"><span class="pre">generation_num</span></code> and <code class="docutils literal notranslate"><span class="pre">strategy_population</span></code> are, the longer the calibration process will take, but also the higher quality the results will be in general.</p></li>
<li><p>Fourth, to evaluate the uncertainty of the GA-based calibration process, <code class="docutils literal notranslate"><span class="pre">Melodie</span></code> also provides the <code class="docutils literal notranslate"><span class="pre">path_num</span></code> parameter that decides how many times the calibration process is done.</p></li>
<li><p>Finally, <code class="docutils literal notranslate"><span class="pre">Melodie</span></code> also supports batching calibration runs. Each run is a combination of one row in the <code class="docutils literal notranslate"><span class="pre">CalibratorScenarios.xlsx</span></code> file and another row in the <code class="docutils literal notranslate"><span class="pre">CalibratorParamsScenarios.xlsx</span></code> file. You only need to edit these two files and <code class="docutils literal notranslate"><span class="pre">Melodie</span></code> will automatically iterate through all the combinations for you.</p></li>
</ul>
<p>Regarding the coding of parameter, for example,
if we want to code a parameter ranging in <span class="math notranslate nohighlight">\([0, a]\)</span> with a five-digit binary series.
First, map the five-digit binary number to a decimal number.
Second, divide the number by 31, which is the biggest decimal number that a five-digit binary number can represent,
then we get a number x in range <span class="math notranslate nohighlight">\([0, 1]\)</span>.
Third, scale x to the range <span class="math notranslate nohighlight">\([0, a]\)</span> linearly.
As a result, <span class="math notranslate nohighlight">\(01001\)</span> is translated as <span class="math notranslate nohighlight">\(x = 9a/31\)</span>.</p>
</section>
<section id="results">
<h2>Results<a class="headerlink" href="#results" title="Permalink to this heading"></a></h2>
<p>After running the <code class="docutils literal notranslate"><span class="pre">run_calibrator.py</span></code> file, if you see following messages (or similar) printed,
it means the calibration process successfully went through.</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>calibrator.py:391 <span class="nv">INFO</span> <span class="o">====================</span>Time Elapsed: <span class="m">2</span>.0582101345062256s<span class="o">====================</span>
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc2e0f10&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc361a60&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc3585b0&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc487820&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc358190&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc459430&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc257880&gt;
parallel_manager.py:110 INFO terminated subworker &lt;subprocess.Popen object at 0x7f87bc2572e0&gt;
server.py:123 INFO listener closed
server.py:207 INFO goodbye <span class="o">(</span><span class="s1">&#39;127.0.0.1&#39;</span>, <span class="m">51509</span><span class="o">)</span>
server.py:207 INFO goodbye <span class="o">(</span><span class="s1">&#39;127.0.0.1&#39;</span>, <span class="m">51511</span><span class="o">)</span>
server.py:271 INFO server has terminated
server.py:123 INFO listener closed
parallel_manager.py:113 INFO Server closed!
</pre></div>
</div>
<p>Then, you will find two result table in the database.</p>
<p>First is the <code class="docutils literal notranslate"><span class="pre">environment_calibrator_result</span></code> table:</p>
<img alt="../_images/calibrator_results.png" src="../_images/calibrator_results.png" />
<p>Second is the <code class="docutils literal notranslate"><span class="pre">environment_calibrator_result_cov</span></code> table:</p>
<img alt="../_images/calibrator_results_cov.png" src="../_images/calibrator_results_cov.png" />
<p>As shown, <code class="docutils literal notranslate"><span class="pre">environment_calibrator_result</span></code> has one more index column, the <code class="docutils literal notranslate"><span class="pre">id_chromosome</span></code> column.
Then, <code class="docutils literal notranslate"><span class="pre">environment_calibrator_result_cov</span></code> calculates the <code class="docutils literal notranslate"><span class="pre">mean</span></code> and <code class="docutils literal notranslate"><span class="pre">coefficient</span> <span class="pre">of</span> <span class="pre">variance</span></code> (<span class="math notranslate nohighlight">\(\mu / \sigma\)</span>)
of <code class="docutils literal notranslate"><span class="pre">infection_prob</span></code>, <code class="docutils literal notranslate"><span class="pre">s0</span></code>, and <code class="docutils literal notranslate"><span class="pre">distance</span></code> in each generation.</p>
<p>On top of the tutorial model,
one more function - <code class="docutils literal notranslate"><span class="pre">plot_calibration_process</span></code> - is added to plot the calibration process.
By calling it in the <code class="docutils literal notranslate"><span class="pre">run_analyzer.py</span></code> file,
two figures are produced based on the results in <code class="docutils literal notranslate"><span class="pre">environment_calibrator_result_cov</span></code> and saved in the <code class="docutils literal notranslate"><span class="pre">data/output</span></code> folder.
They are shown below.</p>
<img alt="../_images/calibrator_infection_prob.png" src="../_images/calibrator_infection_prob.png" />
<img alt="../_images/calibrator_s0.png" src="../_images/calibrator_s0.png" />
<p>For more details of the <code class="docutils literal notranslate"><span class="pre">Calibrator</span></code> module, please refer to the <a class="reference internal" href="../api/_index.html#api-reference"><span class="std std-ref">API Reference</span></a> section.</p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="covid_network_contagion.html" class="btn btn-neutral float-left" title="CovidNetworkContagion" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="rock_paper_scissors.html" class="btn btn-neutral float-right" title="RockPaperScissorsTrainer" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2021-2022, ABM4ALL.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>